package com.hp.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hp.bean.Customerservice;
import com.hp.bean.Master;
import com.hp.bean.MasterExample;
import com.hp.mapper.MasterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class MasterServiceImpl implements MasterService {
    @Resource
    private MasterMapper mapper;


    @Override
    public Master login(MasterExample obj) {
        List<Master> list = mapper.selectByExample(obj);
        if(list!=null&&list.size()>0){
            return list.get(0);
        }else {
            return null;
        }
    }

    @Override
    public List<Master> find(MasterExample obj, Integer page, Integer limt) {
       return mapper.selectByExample(obj);
    }

    @Override
    public Master findByid(Integer id) {
        return mapper.selectByPrimaryKey(id);

    }

    @Override
    public int add(Master obj) {
        return mapper.insertSelective(obj);
    }

    @Override
    public int upp(Master obj) {
        return mapper.updateByPrimaryKeySelective(obj);
    }

    @Override
    public int del(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<Master> pageFind(MasterExample example, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<Master> list = mapper.selectExample(example);
        PageInfo<Master> pageInfo = new PageInfo<Master>(list);
        return pageInfo;
    }

    @Override
    public List<Master> selectMasterList(Master obj) {
        return mapper.selectMasterList(obj);
    }
}
